{
  "properties" : { },
  "id" : "ed0d32de5faf4fc6a43765f17820ca0d",
  "script" : null,
  "groupId" : "23234bfccdc54495a21a41d64ab0ed00",
  "name" : "获取模型数据",
  "createTime" : 1727070860812,
  "updateTime" : 1726711189806,
  "lock" : "0",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "getValue",
  "method" : "GET",
  "parameters" : [ {
    "name" : "name",
    "value" : "deviceNetIf",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  }, {
    "name" : "deviceId",
    "value" : "D3761420980988602955",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": [\n        {\n            \"id\": \"1656476788692398082\",\n            \"name\": \"设备接口信息\",\n            \"parentId\": \"\",\n            \"type\": \"表格模型\",\n            \"childList\": [],\n            \"attributeList\": [\n                {\n                    \"displayName\": \"接口类型\",\n                    \"name\": \"ifType\",\n                    \"sort\": \"27\",\n                    \"time\": \"2024-06-14 10:18:23.049\",\n                    \"width\": \"33%\",\n                    \"value\": {\n                        \"1\": \"1\",\n                        \"2\": \"6\",\n                        \"3\": \"6\",\n                        \"4\": \"6\",\n                        \"5\": \"1\",\n                        \"6\": \"1\",\n                        \"545\": \"23\",\n                        \"546\": \"23\",\n                        \"547\": \"23\",\n                        \"548\": \"23\",\n                        \"17410\": \"1\",\n                        \"17411\": \"24\",\n                        \"17412\": \"1\",\n                        \"17413\": \"24\"\n                    }\n                },\n                {\n                    \"displayName\": \"接口ip\",\n                    \"name\": \"ifIp\",\n                    \"sort\": \"28\",\n                    \"time\": \"2024-06-14 10:18:23.049\",\n                    \"width\": \"33%\",\n                    \"value\": {}\n                },\n                {\n                    \"displayName\": \"接口描述\",\n                    \"name\": \"ifDescr\",\n                    \"sort\": \"25\",\n                    \"time\": \"2024-06-14 10:18:22.087\",\n                    \"width\": \"33%\",\n                    \"value\": {\n                        \"1\": \"Aux0\",\n                        \"2\": \"GigabitEthernet0/0\",\n                        \"3\": \"GigabitEthernet0/1\",\n                        \"4\": \"GigabitEthernet0/2\",\n                        \"5\": \"Cellular0/0\",\n                        \"6\": \"Cellular0/1\",\n                        \"545\": \"Serial8/0\",\n                        \"546\": \"Serial8/1\",\n                        \"547\": \"Serial8/2\",\n                        \"548\": \"Serial8/3\",\n                        \"17410\": \"NULL0\",\n                        \"17411\": \"InLoopBack0\",\n                        \"17412\": \"Register-Tunnel0\",\n                        \"17413\": \"LoopBack0\"\n                    }\n                },\n                {\n                    \"displayName\": \"接口MAC地址\",\n                    \"name\": \"ifPhysAddress\",\n                    \"sort\": \"24\",\n                    \"time\": \"2024-06-14 10:18:19.050\",\n                    \"width\": \"33%\",\n                    \"value\": {\n                        \"1\": \"00:00:00:00:00:00\",\n                        \"2\": \"38:ad:8e:ae:c4:3b\",\n                        \"3\": \"38:ad:8e:ae:c4:3c\",\n                        \"4\": \"38:ad:8e:ae:c4:3d\",\n                        \"5\": \"00:00:00:00:00:00\",\n                        \"6\": \"00:00:00:00:00:00\",\n                        \"545\": \"00:00:00:00:00:00\",\n                        \"546\": \"00:00:00:00:00:00\",\n                        \"547\": \"00:00:00:00:00:00\",\n                        \"548\": \"00:00:00:00:00:00\",\n                        \"17410\": \"00:00:00:00:00:00\",\n                        \"17411\": \"00:00:00:00:00:00\",\n                        \"17412\": \"00:00:00:00:00:00\",\n                        \"17413\": \"00:00:00:00:00:00\"\n                    }\n                },\n                {\n                    \"displayName\": \"接口速率\",\n                    \"name\": \"ifFlowSpeed\",\n                    \"sort\": \"29\",\n                    \"time\": \"2024-06-14 13:09:36.055\",\n                    \"width\": \"33%\",\n                    \"value\": {\n                        \"1\": \"0\",\n                        \"2\": \"552\",\n                        \"3\": \"44\",\n                        \"4\": \"0\",\n                        \"545\": \"964\",\n                        \"546\": \"0\",\n                        \"547\": \"0\",\n                        \"548\": \"0\",\n                        \"17410\": \"0\",\n                        \"17411\": \"0\",\n                        \"17412\": \"0\",\n                        \"17413\": \"0\"\n                    }\n                },\n                {\n                    \"displayName\": \"接口别名\",\n                    \"name\": \"if_alais\",\n                    \"sort\": \"23\",\n                    \"time\": \"2024-06-14 13:09:36.055\",\n                    \"width\": \"33%\",\n                    \"value\": []\n                },\n                {\n                    \"displayName\": \"实际带宽\",\n                    \"name\": \"ifHighSpeed\",\n                    \"sort\": \"26\",\n                    \"time\": \"2024-06-14 13:09:36.055\",\n                    \"width\": \"33%\",\n                    \"value\": {}\n                }\n            ]\n        }\n    ]\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  }
}
================================
import cn.hutool.core.util.StrUtil
import redis
models = db.select("""
    SELECT * from ndmp_dynamic_model
    where parent_id = (SELECT model_id FROM ndmp_path_model_relation where path = #{name})
           or id = (SELECT model_id FROM ndmp_path_model_relation where path = #{name})
""")
fields = db.select("""
    SELECT a.*,r.model_id model_id from ndmp_dynamic_model_attribute a,ndmp_dynamic_model_relation r
    where r.column_id = a.id
    and r.model_id in 
    <foreach item="item" collection="models" separator="," open="(" close=")" >
        #{item.id}
    </foreach>
""")

return models.map(m -> {
    m.childList = []
    flag = 1
    List attributeList = fields.map(f -> {
        var time
        var value = {}
        var displayName = f.fromField
        if (StrUtil.equalsAny(f.fromDb, "2", "5")) {
            f.fromField = f.fromTable
            point = redis.getPoint(deviceId, f.fromTable)
            if (point != null) {
                time = point.time
                if (StrUtil.equals("标量模型", m.type)) {
                    value = point.value.get("0")
                } else {
                    value = point.value
                }
            }

        } else if (StrUtil.equalsAny(f.fromDb, "3")) {
            flag = 0
            value = db.table(f.fromTable)
                .column(f.fromField.toLowerCase())
                .where()
                .eq(StrUtil.equalsAnyIgnoreCase(f.fromTable, "ndmp_device") ? "id" : "device_id", deviceId)
                .select()
                .map(r -> r.get(StrUtil.toCamelCase(f.fromField.toLowerCase())))
        }
        return {
            "displayName": f.name,
            "name": f.fromField,
            "sort": f.sort,
            "time": time,
            "width": f.width,
            "value": value
        }

    })
    if (flag == 1) {
        keys = attributeList.stream().max((a, b) -> Integer.compare(a.value.size(), b.value.size())).map(r -> r.value.keySet()).orElse(null);
        attributeList.each(r -> {
            newValue = new ArrayList()
            keys.each(k -> {
                newValue.add(r.value.get(k))
            })
            r.value = newValue
        })
    }
    m.attributeList = attributeList
    return m
})